package com.xdcplus.web.controller.trace;


import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.web.handler.PacketTraceWashHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "追溯清洗")
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("prdInfoTrace")
public class PacketTraceWashController extends AbstractController {

    @Autowired
    private PacketTraceWashHandler packetTraceWashHandler;

    @ApiOperation("小包")
    @PostMapping(value = "/test", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO getPrdInfoTrace(@RequestParam("num") int num) {
        for (int i = 0; i < num; i++) {

            new Thread(()->{
                while (true) {
                    try {
                        packetTraceWashHandler.washPacketBatchInfo();
                        Thread.sleep(20L);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }).start();

        }
        return ResponseVO.success();
    }


}
